News All Tests
Current file: /home/estudydev/workspace/MSP09/web/news/tests/class.ressourcendb.inc.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 16
1.32 %1.32%
1.32% 2 / 151
 
RessourcenDB
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 16
0.68 %0.68%
0.68% 1 / 148
 public function __construct($fileManager = NULL)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public function setFileManager($filemanager)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public static function getVisibilityConstraintSQL()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 13
 public function getSubFolder($p_folder)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 12
 public static function saveFolderState($folder)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 11
 private function getFileObject($db_object)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 16
 private function getFolderObject($folder_db)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 11
 public function getFiles($folderID, $sortString = 'create_time', $desc = false)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 15
 public function getNewestFiles($limit = 20)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 10
 public function getMostRatedFiles($limit = 20)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 10
 public function getFileByID($fileID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 6
 public function getFolderByID($folderID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 6
 public function getUserCourses($userID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 12
 public function countSubElements($folderID, $subFolders = true)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 12
 public function getCourseShortNameByID($courseID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 3
 public function logResourceDownload($resourceID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 6


       1                 : <?php                                                                                                                                                                                                                                                                                                                                                                                                  
       2                 : /*--------------------------------------------------------------------------+                                                                                                                                                                                                                                                                                                                          
       3                 : This file is part of eStudy.                                                                                                                                                                                                                                                                                                                                                                           
       4                 : ressourcen/classes/filemanager/class.ressourcendb.inc.php                                                                                                                                                                                                                                                                                                                                              
       5                 : - Modulgruppe:  File Manager                                                                                                                                                                                                                                                                                                                                                                           
       6                 : - Beschreibung: Klasse zur Datenbankanbindung                                                                                                                                                                                                                                                                                                                                                          
       7                 : - Version:      0.4, 08.01.08                                                                                                                                                                                                                                                                                                                                                                          
       8                 : - Autor(en):    Tobias Wild <tobias.wild@mni.fh-giessen.de>                                                                                                                                                                                                                                                                                                                                            
       9                 : +---------------------------------------------------------------------------+                                                                                                                                                                                                                                                                                                                          
      10                 : This program is free software; you can redistribute it and/or                                                                                                                                                                                                                                                                                                                                          
      11                 : modify it under the terms of the GNU General Public License                                                                                                                                                                                                                                                                                                                                            
      12                 : as published by the Free Software Foundation; either version 2                                                                                                                                                                                                                                                                                                                                         
      13                 : of the License, or any later version.                                                                                                                                                                                                                                                                                                                                                                  
      14                 : +---------------------------------------------------------------------------+                                                                                                                                                                                                                                                                                                                          
      15                 : This program is distributed in the hope that it will be useful,                                                                                                                                                                                                                                                                                                                                        
      16                 : but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                                                                                                                                                                                                                                                                                         
      17                 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                                                                                                                                                                                                                                                                                                          
      18                 : GNU General Public License for more details.                                                                                                                                                                                                                                                                                                                                                           
      19                 : You should have received a copy of the GNU General Public License                                                                                                                                                                                                                                                                                                                                      
      20                 : along with this program; if not, write to the Free Software                                                                                                                                                                                                                                                                                                                                            
      21                 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                                                                                                                                                                                                                                                                                                            
      22                 : +--------------------------------------------------------------------------*/                                                                                                                                                                                                                                                                                                                          
      23                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      24               1 : if ( !defined("PATH_TO_ROOT") ) {                                                                                                                                                                                                                                                                                                                                                                      
      25               0 :     define( "PATH_TO_ROOT", "../../" );                                                                                                                                                                                                                                                                                                                                                                
      26               0 : }                                                                                                                                                                                                                                                                                                                                                                                                      
      27                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      28               1 : class RessourcenDB {                                                                                                                                                                                                                                                                                                                                                                                   
      29                 :     private $fileManager = null;                                                                                                                                                                                                                                                                                                                                                                       
      30                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      31                 :     public function __construct( $fileManager = null ) {                                                                                                                                                                                                                                                                                                                                               
      32               0 :         $this->fileManager = $fileManager;                                                                                                                                                                                                                                                                                                                                                             
      33               0 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
      34                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      35                 :     public function setFileManager( $filemanager ) {                                                                                                                                                                                                                                                                                                                                                   
      36               0 :         $this->fileManager = $filemanager;                                                                                                                                                                                                                                                                                                                                                             
      37               0 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
      38                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      39                 :     public static function getVisibilityConstraintSQL() {                                                                                                                                                                                                                                                                                                                                              
      40               0 :         global $db, $settings;                                                                                                                                                                                                                                                                                                                                                                         
      41               0 :         $time = Data::toMysql( time() );                                                                                                                                                                                                                                                                                                                                                               
      42               0 :         $userid = Data::toMysql( $_SESSION["userid"] );                                                                                                                                                                                                                                                                                                                                                
      43               0 :         $sql_add = "";                                                                                                                                                                                                                                                                                                                                                                                 
      44               0 :         if ($_SESSION['usergroup'] == STUDENT || $_SESSION['usergroup'] == ALUMNUS || $_SESSION['usergroup'] == SCHUELER || $_SESSION['usergroup'] == GAST || $_SESSION["usergroup"] == SEKRETARIAT) { // Hier darf kein visible_type eingeschraenkt werden, da sonst die Einzeluser-Berechtigung nicht mehr funktioniert !!!                                                                          
      45               0 :             $sql_add = "AND ((filelist.userID='".$userid."' OR (start_time<'$time' AND end_time>'$time' AND visible_type=1))";                                                                                                                                                                                                                                                                         
      46               0 :             if (isset($_SESSION["assistent"])) // TUTOR                                                                                                                                                                                                                                                                                                                                                
      47               0 :             $sql_add = "AND ((visible_type<='2' OR filelist.userID='".$userid."')";                                                                                                                                                                                                                                                                                                                    
      48               0 :             $visibleFiles = $db->get_col("SELECT fileID FROM filevisible WHERE userID='".$userid."'");                                                                                                                                                                                                                                                                                                 
      49               0 :             if ($db->num_rows) $sql_add.= " OR fileID IN (".implode(",", $visibleFiles) .")";                                                                                                                                                                                                                                                                                                          
      50               0 :             $sql_add.= ")";                                                                                                                                                                                                                                                                                                                                                                            
      51               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
      52               0 :         return $sql_add;                                                                                                                                                                                                                                                                                                                                                                               
      53                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
      54                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      55                 :     public function getSubFolder( $p_folder ) {                                                                                                                                                                                                                                                                                                                                                        
      56               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
      57               0 :         $sql_add = self::getVisibilityConstraintSQL();                                                                                                                                                                                                                                                                                                                                                 
      58               0 :         $folderID = Data::toMysql( $p_folder->getID() );                                                                                                                                                                                                                                                                                                                                               
      59               0 :         $folders_db = (array) $db->get_results("SELECT courseID, create_time, description, student_write, userID, fileID, link, visible_type, name FROM filelist WHERE parent_object='".$folderID."' AND courseID='".Data::toMysql( $_SESSION['course'] )."' AND type='folder' $sql_add ORDER BY link");                                                                                               
      60               0 :         $folders = array();                                                                                                                                                                                                                                                                                                                                                                            
      61               0 :         foreach ( $folders_db as $folder_db ) {                                                                                                                                                                                                                                                                                                                                                        
      62               0 :             $folder = $this->getFolderObject( $folder_db );                                                                                                                                                                                                                                                                                                                                            
      63               0 :             $folder->setParentFolder( $p_folder );                                                                                                                                                                                                                                                                                                                                                     
      64               0 :             $folder->setFolderState( $db->get_var("SELECT userID FROM filetreelayout WHERE userID='".Data::toMysql( $_SESSION['userid'] )."' AND folderID='".Data::toMysql( $folder_db->fileID )."'") );                                                                                                                                                                                               
      65               0 :             $folders[] = $folder;                                                                                                                                                                                                                                                                                                                                                                      
      66               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
      67               0 :         return $folders;                                                                                                                                                                                                                                                                                                                                                                               
      68                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
      69                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      70                 :     public static function saveFolderState( $folder ) {                                                                                                                                                                                                                                                                                                                                                
      71               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
      72               0 :         $folderState = $folder->getFolderState();                                                                                                                                                                                                                                                                                                                                                      
      73               0 :         $userid = Data::toMysql( $_SESSION['userid'] );                                                                                                                                                                                                                                                                                                                                                
      74               0 :         $folderID = Data::toMysql( $folder->getID() );                                                                                                                                                                                                                                                                                                                                                 
      75               0 :         if ($folderState) {                                                                                                                                                                                                                                                                                                                                                                            
      76               0 :             $db->query("DELETE FROM filetreelayout WHERE userID='".$userid."' AND folderID='".$folderID."'");                                                                                                                                                                                                                                                                                          
      77               0 :             $folder->setFolderState(false);                                                                                                                                                                                                                                                                                                                                                            
      78               0 :         } else {                                                                                                                                                                                                                                                                                                                                                                                       
      79               0 :             $db->query("INSERT INTO filetreelayout (userID, folderID) VALUES ('".$userid."','".$folderID."')");                                                                                                                                                                                                                                                                                        
      80               0 :             $folder->setFolderState(true);                                                                                                                                                                                                                                                                                                                                                             
      81                 :         }                                                                                                                                                                                                                                                                                                                                                                                              
      82               0 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
      83                 :                                                                                                                                                                                                                                                                                                                                                                                                        
      84                 :     private function getFileObject( $db_object ) {                                                                                                                                                                                                                                                                                                                                                     
      85               0 :         $file = new File();                                                                                                                                                                                                                                                                                                                                                                            
      86               0 :         $file->setFileID ( $db_object->fileID );                                                                                                                                                                                                                                                                                                                                                       
      87               0 :         $file->setVisibleType ( $db_object->visible_type );                                                                                                                                                                                                                                                                                                                                            
      88               0 :         $file->setUserID ( $db_object->userID );                                                                                                                                                                                                                                                                                                                                                       
      89               0 :         $file->setName ( $db_object->name );                                                                                                                                                                                                                                                                                                                                                           
      90               0 :         $file->setOrigFileName ( $db_object->orig_filename );                                                                                                                                                                                                                                                                                                                                          
      91               0 :         $file->setType ( $db_object->type );                                                                                                                                                                                                                                                                                                                                                           
      92               0 :         $file->setLink ( $db_object->link );                                                                                                                                                                                                                                                                                                                                                           
      93               0 :         $file->setSize ( $db_object->size );                                                                                                                                                                                                                                                                                                                                                           
      94               0 :         $file->setCounter ( $db_object->counter );                                                                                                                                                                                                                                                                                                                                                     
      95               0 :         $file->setCreateTime ( $db_object->create_time );                                                                                                                                                                                                                                                                                                                                              
      96               0 :         $file->setDescription ( $db_object->description );                                                                                                                                                                                                                                                                                                                                             
      97               0 :         $file->setExtension ( $db_object->extension );                                                                                                                                                                                                                                                                                                                                                 
      98               0 :         $file->setCourseID ( $db_object->courseID );                                                                                                                                                                                                                                                                                                                                                   
      99               0 :         $file->setFileManager( $this->fileManager );                                                                                                                                                                                                                                                                                                                                                   
     100               0 :         return $file;                                                                                                                                                                                                                                                                                                                                                                                  
     101                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     102                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     103                 :     private function getFolderObject( $folder_db ) {                                                                                                                                                                                                                                                                                                                                                   
     104               0 :         $folder = new Folder( $folder_db->fileID );                                                                                                                                                                                                                                                                                                                                                    
     105               0 :         $folder->setCourseID( $folder_db->courseID );                                                                                                                                                                                                                                                                                                                                                  
     106               0 :         $folder->setUserID( $folder_db->userID );                                                                                                                                                                                                                                                                                                                                                      
     107               0 :         $folder->setLink( $folder_db->link );                                                                                                                                                                                                                                                                                                                                                          
     108               0 :         $folder->setVisibleType( $folder_db->visible_type );                                                                                                                                                                                                                                                                                                                                           
     109               0 :         $folder->setName( $folder_db->name );                                                                                                                                                                                                                                                                                                                                                          
     110               0 :         $folder->setStudentWrite( $folder_db->student_write );                                                                                                                                                                                                                                                                                                                                         
     111               0 :         $folder->setCreateTime( $folder_db->create_time );                                                                                                                                                                                                                                                                                                                                             
     112               0 :         $folder->setDescription( $folder_db->description );                                                                                                                                                                                                                                                                                                                                            
     113               0 :         $folder->setFileManager( $this->fileManager );                                                                                                                                                                                                                                                                                                                                                 
     114               0 :         return $folder;                                                                                                                                                                                                                                                                                                                                                                                
     115                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     116                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     117                 :     public function getFiles( $folderID, $sortString = "create_time" , $desc = false ) {                                                                                                                                                                                                                                                                                                               
     118               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     119               0 :         $course = Data::toMysql( $_SESSION["course"] );                                                                                                                                                                                                                                                                                                                                                
     120               0 :         $direction = ( $desc ) ? "DESC" : "ASC";                                                                                                                                                                                                                                                                                                                                                       
     121               0 :         $sortString = Data::toMysql( $sortString );                                                                                                                                                                                                                                                                                                                                                    
     122               0 :         $folderID = Data::toMysql( $folderID );                                                                                                                                                                                                                                                                                                                                                        
     123                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     124               0 :         $sql_add = self::getVisibilityConstraintSQL();                                                                                                                                                                                                                                                                                                                                                 
     125               0 :         if ( $sortString == "userID" ) {                                                                                                                                                                                                                                                                                                                                                               
     126               0 :             $files_db = (array) $db->get_results("SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter, create_time, description, extension, courseID FROM filelist LEFT OUTER JOIN user ON (filelist.userID=user.ID) WHERE parent_object='".$folderID."' AND (courseID=$course OR courseID=0)  AND type!='folder' $sql_add ". " ORDER BY user.Nachname " . $direction);
     127               0 :         } else {                                                                                                                                                                                                                                                                                                                                                                                       
     128               0 :             $files_db = (array) $db->get_results("SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter, create_time, description, extension, courseID FROM filelist WHERE parent_object='".$folderID."' AND (courseID='$course' OR courseID=0) AND type!='folder' ".$sql_add." ORDER BY ".$sortString. " ". $direction);                                                
     129                 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     130               0 :         $files = array();                                                                                                                                                                                                                                                                                                                                                                              
     131               0 :         foreach ( $files_db as $file_db ) {                                                                                                                                                                                                                                                                                                                                                            
     132               0 :             $files[] = self::getFileObject( $file_db );                                                                                                                                                                                                                                                                                                                                                
     133               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     134               0 :         return $files;                                                                                                                                                                                                                                                                                                                                                                                 
     135                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     136                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     137                 :     public function getNewestFiles( $limit = 20 ) {                                                                                                                                                                                                                                                                                                                                                    
     138               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     139               0 :         $time = time();                                                                                                                                                                                                                                                                                                                                                                                
     140               0 :         $course = Data::toMysql( $_SESSION["course"] );                                                                                                                                                                                                                                                                                                                                                
     141               0 :         $limit = Data::toMysql( $limit );                                                                                                                                                                                                                                                                                                                                                              
     142               0 :         $files_db = (array) $db->get_results("SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter, create_time, description, extension, courseID FROM filelist WHERE courseID='$course' AND visible_type=1 AND type!='folder' AND start_time<'$time' AND end_time>'$time' ORDER BY create_time DESC LIMIT $limit");                                                    
     143               0 :         $files = array();                                                                                                                                                                                                                                                                                                                                                                              
     144               0 :         foreach ( $files_db as $file_db ) {                                                                                                                                                                                                                                                                                                                                                            
     145               0 :             $files[] = self::getFileObject( $file_db );                                                                                                                                                                                                                                                                                                                                                
     146               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     147               0 :         return $files;                                                                                                                                                                                                                                                                                                                                                                                 
     148                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     149                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     150                 :     public function getMostRatedFiles( $limit = 20 ) {                                                                                                                                                                                                                                                                                                                                                 
     151               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     152               0 :         $time = time();                                                                                                                                                                                                                                                                                                                                                                                
     153               0 :         $course = Data::toMysql( $_SESSION["course"] );                                                                                                                                                                                                                                                                                                                                                
     154               0 :         $limit = Data::toMysql( $limit );                                                                                                                                                                                                                                                                                                                                                              
     155               0 :         $files_db = (array) $db->get_results("SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter, create_time, description, extension, courseID FROM filelist WHERE courseID='$course' AND visible_type=1 AND type!='folder' AND start_time<'$time' AND end_time>'$time' ORDER BY counter DESC LIMIT $limit");                                                        
     156               0 :         $files = array();                                                                                                                                                                                                                                                                                                                                                                              
     157               0 :         foreach ( $files_db as $file_db ) {                                                                                                                                                                                                                                                                                                                                                            
     158               0 :             $files[] = self::getFileObject( $file_db );                                                                                                                                                                                                                                                                                                                                                
     159               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     160               0 :         return $files;                                                                                                                                                                                                                                                                                                                                                                                 
     161                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     162                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     163                 :     public function getFileByID( $fileID ) {                                                                                                                                                                                                                                                                                                                                                           
     164               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     165               0 :         $fileID = Data::toMysql( $fileID );                                                                                                                                                                                                                                                                                                                                                            
     166               0 :         $file_db = $db->get_row("SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter, create_time, description, extension, courseID FROM filelist WHERE fileID = '$fileID' AND type='file'");                                                                                                                                                                          
     167               0 :         if ( $file_db ) {                                                                                                                                                                                                                                                                                                                                                                              
     168               0 :             return $this->getFileObject( $file_db );                                                                                                                                                                                                                                                                                                                                                   
     169                 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     170               0 :         return false;                                                                                                                                                                                                                                                                                                                                                                                  
     171                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     172                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     173                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     174                 :     public function getFolderByID( $folderID ) {                                                                                                                                                                                                                                                                                                                                                       
     175               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     176               0 :         $folderID = Data::toMysql( $folderID );                                                                                                                                                                                                                                                                                                                                                        
     177               0 :         $folder_db = $db->get_row("SELECT name, fileID, courseID, link, userID, student_write, create_time, description, visible_type FROM filelist WHERE type='folder' AND fileID='".$folderID."'");                                                                                                                                                                                                  
     178               0 :         if ( $folder_db ) {                                                                                                                                                                                                                                                                                                                                                                            
     179               0 :             return $this->getFolderObject( $folder_db );                                                                                                                                                                                                                                                                                                                                               
     180                 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     181               0 :         return false;                                                                                                                                                                                                                                                                                                                                                                                  
     182                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     183                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     184                 :     public function getUserCourses( $userID ) {                                                                                                                                                                                                                                                                                                                                                        
     185               0 :         global $settings, $db;                                                                                                                                                                                                                                                                                                                                                                         
     186               0 :         $userID = Data::toMysql( $userID );                                                                                                                                                                                                                                                                                                                                                            
     187               0 :         $courseID = Data::toMysql( $_SESSION['course'] );                                                                                                                                                                                                                                                                                                                                              
     188               0 :         if ($_SESSION['usergroup'] == ADMIN || $_SESSION['usergroup'] == SEKRETARIAT) $sql = "SELECT c.ID, c.ShortName AS SN, u.ShortName                                                                                                                                                                                                                                                              
     189                 :                                   FROM courses AS c                                                                                                                                                                                                                                                                                                                                                    
     190                 :                                   RIGHT JOIN user_course AS uc                                                                                                                                                                                                                                                                                                                                         
     191                 :                                        ON c.ID = uc.courseID                                                                                                                                                                                                                                                                                                                                           
     192                 :                                   LEFT JOIN user AS u                                                                                                                                                                                                                                                                                                                                                  
     193                 :                                        ON uc.userID = u.ID                                                                                                                                                                                                                                                                                                                                             
     194                 :                                   WHERE ((u.Usergroup = 3 AND uc.differentUsergroup = 0)                                                                                                                                                                                                                                                                                                               
     195                 :                                     OR uc.differentUsergroup = 3)                                                                                                                                                                                                                                                                                                                                      
     196                 :                                     AND c.closed = 0 " .                                                                                                                                                                                                                                                                                                                                               
     197               0 :                                    "AND c.ID <> ". $courseID ."                                                                                                                                                                                                                                                                                                                                        
     198               0 :                                   ORDER BY c.ShortName, c.ID";                                                                                                                                                                                                                                                                                                                                         
     199                 :         else $sql = "SELECT c.ID, c.ShortName AS SN, u.ShortName                                                                                                                                                                                                                                                                                                                                       
     200                 :                           FROM (user_course AS uc1, user AS u)                                                                                                                                                                                                                                                                                                                                         
     201                 :                           RIGHT JOIN user_course AS uc2                                                                                                                                                                                                                                                                                                                                                
     202                 :                            ON uc1.courseID = uc2.courseID                                                                                                                                                                                                                                                                                                                                              
     203                 :                           RIGHT JOIN courses AS c                                                                                                                                                                                                                                                                                                                                                      
     204                 :                            ON uc1.courseID = c.ID                                                                                                                                                                                                                                                                                                                                                      
     205                 :                           WHERE ((u.Usergroup = 3 AND uc2.differentUsergroup = 0)                                                                                                                                                                                                                                                                                                                      
     206                 :                             OR uc2.differentUsergroup = 3)                                                                                                                                                                                                                                                                                                                                             
     207               0 :                             AND uc1.userID  = ".$userID."                                                                                                                                                                                                                                                                                                                                              
     208                 :                             AND u.ID        = uc2.userID                                                                                                                                                                                                                                                                                                                                               
     209               0 :                             AND c.closed    = 0 " .                                                                                                                                                                                                                                                                                                                                                    
     210               0 :                             "AND c.ID <> ". $courseID ."                                                                                                                                                                                                                                                                                                                                               
     211               0 :                           ORDER BY c.ShortName, c.ID";                                                                                                                                                                                                                                                                                                                                                 
     212               0 :         $courses = (array) $db->get_results($sql);                                                                                                                                                                                                                                                                                                                                                     
     213                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     214               0 :         return $courses;                                                                                                                                                                                                                                                                                                                                                                               
     215                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     216                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     217                 :     function countSubElements($folderID, $subFolders = true) {                                                                                                                                                                                                                                                                                                                                         
     218               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     219               0 :         $count = 0;                                                                                                                                                                                                                                                                                                                                                                                    
     220               0 :         $folderID = Data::toMysql( $folderID );                                                                                                                                                                                                                                                                                                                                                        
     221               0 :         $sql_add = self::getVisibilityConstraintSQL();                                                                                                                                                                                                                                                                                                                                                 
     222               0 :         if ($subFolders) {                                                                                                                                                                                                                                                                                                                                                                             
     223               0 :             $folders = $db->get_col("SELECT fileID FROM filelist WHERE type='folder' AND parent_object='".$folderID."' ".$sql_add);                                                                                                                                                                                                                                                                    
     224               0 :             if ($folders) foreach($folders as $folder) {                                                                                                                                                                                                                                                                                                                                               
     225               0 :                 $count+= $this->countSubElements($folder);                                                                                                                                                                                                                                                                                                                                             
     226               0 :             }                                                                                                                                                                                                                                                                                                                                                                                          
     227               0 :         }                                                                                                                                                                                                                                                                                                                                                                                              
     228               0 :         $count+= $db->get_var("SELECT COUNT(*) FROM filelist WHERE type!='folder' AND parent_object='$folderID' $sql_add");                                                                                                                                                                                                                                                                            
     229               0 :         return $count;                                                                                                                                                                                                                                                                                                                                                                                 
     230                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     231                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     232                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     233                 :     /**                                                                                                                                                                                                                                                                                                                                                                                                
     234                 :      * Get short course name.                                                                                                                                                                                                                                                                                                                                                                          
     235                 :      *                                                                                                                                                                                                                                                                                                                                                                                                 
     236                 :      * @param Integer $courseID Course id                                                                                                                                                                                                                                                                                                                                                              
     237                 :      * @return String Short course name                                                                                                                                                                                                                                                                                                                                                                
     238                 :      */                                                                                                                                                                                                                                                                                                                                                                                                
     239                 :     function getCourseShortNameByID($courseID) {                                                                                                                                                                                                                                                                                                                                                       
     240               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     241                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     242               0 :         $courseID = Data::toMysql($courseID);                                                                                                                                                                                                                                                                                                                                                          
     243                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     244               0 :         return $db->get_var("SELECT `ShortName` FROM `courses` WHERE `ID` = $courseID");                                                                                                                                                                                                                                                                                                               
     245                 :     }                                                                                                                                                                                                                                                                                                                                                                                                  
     246                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     247                 :     /**                                                                                                                                                                                                                                                                                                                                                                                                
     248                 :      * Log file download.                                                                                                                                                                                                                                                                                                                                                                              
     249                 :      *                                                                                                                                                                                                                                                                                                                                                                                                 
     250                 :      * Write log entry to filelog table and increment download count in filelist table.                                                                                                                                                                                                                                                                                                                
     251                 :      *                                                                                                                                                                                                                                                                                                                                                                                                 
     252                 :      * @param Integer $resourceID Resource id                                                                                                                                                                                                                                                                                                                                                          
     253                 :      */                                                                                                                                                                                                                                                                                                                                                                                                
     254                 :     public function logResourceDownload($resourceID) {                                                                                                                                                                                                                                                                                                                                                 
     255               0 :         global $db;                                                                                                                                                                                                                                                                                                                                                                                    
     256                 :                                                                                                                                                                                                                                                                                                                                                                                                        
     257               0 :         $time = Data::toMysql(time());                                                                                                                                                                                                                                                                                                                                                                 
     258               0 :         $resourceID = Data::toMysql($resourceID);                                                                                                                                                                                                                                                                                                                                                      
     259               0 :         $db->query("INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid']."','$resourceID','$time')");                                                                                                                                                                                                                                                                             
     260               0 :         $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$resourceID'");                                                                                                                                                                                                                                                                                                                
     261               0 :     }                                                                                                                                                                                                                                                                                                                                                                                                  

Generated by PHPUnit 3.2.21 and Xdebug 2.0.4 at Sat Nov 7 22:04:08 CET 2009.